package com.yanqu.road.server.cmd.activity.mammonhall;

import com.yanqu.road.pb.activity.MammonHallProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.mammonhall.MammonHallModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = GameProtocol.S_MAMMON_HALL_RANK_WORSHIP, desc = "财神殿-膜拜")
public class MammonHallRankWorshipCmd extends AbstractCommand {

    int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MammonHallProto.MammonHallRankWorshipReqMsg reqMsg = MammonHallProto.MammonHallRankWorshipReqMsg.parseFrom(packet.getBytes());
        type = reqMsg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(MammonHallModule.class).worship(type);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            MammonHallProto.MammonHallRankWorshipRespMsg.Builder respMsg = MammonHallProto.MammonHallRankWorshipRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_MAMMON_HALL_RANK_WORSHIP, respMsg);
        }
    }
}
